Skip to content

fix(datagrid): Delete key and right-click respect multi-row/cell-range selection#1648

Open
J2TeamNNL wants to merge 1 commit into
TableProApp:mainfrom
J2TeamNNL:fix/datagrid-d12-delete-multiselect
Open

fix(datagrid): Delete key and right-click respect multi-row/cell-range selection#1648
J2TeamNNL wants to merge 1 commit into
TableProApp:mainfrom
J2TeamNNL:fix/datagrid-d12-delete-multiselect

Conversation

@J2TeamNNL

Copy link
Copy Markdown
Contributor

Root cause

D12Adelete(_:) only read selectedRowIndexes. When cells are selected via drag (grid-range selection), selectedRowIndexes can be empty, so Delete did nothing.

D12B — NSTableView's default rightMouseDown replaces selectedRowIndexes with just the clicked row before menu(for:) is called. By the time the context menu appeared, the multi-row selection was gone.

Fix

D12Adelete(_:) now checks gridSelection.affectedRows first, then falls back to selectedRowIndexes. Mirrors the existing copy() pattern exactly. validateUserInterfaceItem and deleteSelectedRowsIfPossible updated to match.

D12BrightMouseDown override: if the clicked row is already inside the current selection, skip super (which would collapse it) and call NSMenu.popUpContextMenu(_:with:for:) directly.

File: TablePro/Views/Results/KeyHandlingTableView.swift

Test plan

  • Shift/Cmd-click multiple rows, press Delete — all selected rows marked for deletion
  • Drag to select cells spanning multiple rows, press Delete — all covered rows marked for deletion
  • Shift/Cmd-click multiple rows, right-click any row inside the selection — context menu opens with full selection intact
  • Right-click a row outside the current selection — selection moves to clicked row (default behaviour preserved)

…e selection

D12A: delete(_:) checks gridSelection.affectedRows first, mirroring copy().
D12B: rightMouseDown override skips super when clicking inside existing selection,
      calls NSMenu.popUpContextMenu directly to preserve the selection set.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f37596613

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if let controller = gridSelection, !controller.isEmpty {
let rows = controller.selection.affectedRows
guard !rows.isEmpty else { return }
coordinator?.delegate?.dataGridDeleteRows(Set(rows))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear the cell-range selection after deleting inserted rows

When the selected range includes newly inserted rows, dataGridDeleteRows(Set(rows)) physically removes those rows, but the grid selection is left intact: applyRemovedRows only updates/removes table rows and syncSelection performs the next row selection programmatically, so tableViewSelectionDidChange does not clear selectionController. After deleting a cell range over inserted rows, the Delete menu remains enabled from the stale grid selection and pressing Delete again deletes whatever rows shifted into the old indexes.

Useful? React with 👍 / 👎.

override func rightMouseDown(with event: NSEvent) {
let point = convert(event.locationInWindow, from: nil)
let clickedRow = row(at: point)
if clickedRow >= 0, selectedRowIndexes.contains(clickedRow) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve right-clicks inside cell-range selections

This fast path only recognizes rows in selectedRowIndexes, but a grid cell-range selection can span many rows while the NSTableView row selection contains only the focused row. Right-clicking a selected cell on another row falls through to super.rightMouseDown, which selects the clicked row; tableViewSelectionDidChange then clears selectionController when the change is not programmatic, so the context menu still appears after collapsing the cell-range selection. The condition needs to also treat clicks inside gridSelection.selection as selected.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant